package com.bingo.generate.cli.Cmds;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * ClassName
 * Description
 * Create by lc
 * Date 2021/8/9 20:17
 */
public class CompareCmd {

    //  字符串比较
    public static void compareStr(String str1,String str2){
        List<String> list1=strToList(str1);
        List<String> list2=strToList(str2);
        Set<String> set1=new HashSet<>(list1);
        System.out.println("不同的字符串为");
        List<String> diffList=new ArrayList<>();
        for (String s : list2) {
            if(set1.contains(s)){
                continue;
            }
            diffList.add(s);
        }
        System.out.println(diffList);
    }

    public static List strToList(String str){
        List<String> list=new ArrayList<>();
        str=str.replace("\t"," ");
        //  将多个空格替换为一个空格
        str = str.replaceAll( "\\s+", " " );
        String[] strArr = str.split(" ");
        for (String s : strArr) {
            list.add(s);
        }
        return list;
    }

}
